<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>
<head>
<title>买家圈</title>

  <link href="css/goodTop.css" rel="stylesheet" type="text/css" />
  <link rel="stylesheet" type="text/css" href="css/chat.css" />
  <script type="text/javascript" src="js/jquery-1.4.3.min.js"></script>
  <script src="js/jquery-3.1.0.min.js"></script>   

<script>

 var timer;
$(document).ready(function () {
        
        changeFrameHeight();
           $(".content").hide();
            $('.tags a').each(function () {
                if ($(this)[0].href == String(window.location))
                    $(this).addClass('now');
            });
            
              var tl = '${listType}';
            if(tl == "buy"){
                $("#buy").addClass('now');
            }
            
            
            //联系客服
		$("#send").click(function(){
		  
			var content=$("#textarea").val();
			$.ajax({
				type:"post",
				url:"addChat.action",
				data:{content:content},
				success:function(msg){
				}
			});
			$(".chat01_content").append("<div>我:"+content+"</div>");
			$("#textarea").val("");
		});
			
		//结束联系客服
		$(".close_btn").click(function(){
			$.ajax({
				type:"post",
				url:"addChat.action",
				data:{content:"[endchat]"},
				success:function(msg){
					$(".content").hide();
				}
			});
			clearInterval(timer);
		});
          
        });
        
  	var id=-1;
	var getchat=function(){
		$.ajax({
			type:"post",
			url:"getChat.action",
			data:{userFrom:"s10001"},
			success:function(msg){
				if(msg!="fail"){
					var newId=msg.split("_")[0];
					if(id!=newId){ 
						$(".chat01_content").append("<div>"+msg.split("_")[1]+"客服:"+msg.split("_")[4]+"<div style='float:right;margin-right:20px;'>"+msg.split("_")[3]+"</div></div>");
						id=newId;
					}
				}
				
			}
		});
	};
        
        
$(function(){
        var flag = $("#a_01").attr("flag");
    	if(flag=="true"){ //没有登录
		$("#a_01,#a_02,#a_03").click(function(){
			window.parent.location.href="login.jsp";
		});
		
	    }else{  //已经登录
		$("#a_01,#a_02").click(function(){
			window.parent.location.href="personal.jsp";
		}); 
		$("#a_03").click(function(){
				$(".content").show();
				timer=setInterval(getchat,3000);
			});
		}
		
			//注销
				$("#quit").click(function(){
					if(confirm("确认注销？")){
						window.location.href="quit.action";
					}
					
				});
		
		
	});
	
function changeFrameHeight() {
   var iframe= document.getElementById("two"); 
   if (iframe) {
   var iframeWin = iframe.contentWindow;
   if (iframeWin.document.body) {
   iframe.height = iframeWin.document.documentElement.scrollHeight;
    }
  }
};
  

 function search(){
       var name= $("#name").val();
	   buyframe.window.sh(name); 
	}
	
	
	
</script>
<style type="text/css">
#quit{
	position: absolute;
	left: 140px;
	top: 16px;
	font-size:11px;
	font-color:black;
}
</style>

</head>
<body style="background-color:#708090;">
<div id="top1">
    <div class="per1">       
        <a href="#" id="a_01" flag="${user==null}">
		<c:choose><c:when test="${user==null}"><span style="margin-left:4%"></span>未登录</c:when>
			<c:otherwise>
				<img id="myimg" src="uImg/${user.userId}.jpg"/>${user.detailUser.nickName}
				<span><a href="#" id="quit">注销</a></span>
			</c:otherwise>
		</c:choose></a>
	<a href="#" id="a_02">个人中心</a>
	<a href="#" id="a_03">联系客服</a>
    </div>
	<div class="boxtop">

		 <div class="shbox">
			<div class="sh">
				<form action="" method="post">
				    <input type="hidden" id="ty" value="${type}"/>
				    <input type="hidden" id="sea" value="${search}"/>
					<input type="text" name="name" style="width:250px;height:40px" id="name"/>
					<input type="button" value="搜索" style="width:60px;height:40px" id="bt" onclick="search()"/>
				</form>
			</div>
		</div>
	 </div>
	 <div class="tags">
			<a href="home.jsp">首&nbsp; &nbsp;页</a> <a
				href="getGoodbyType.action?good.type=0&good.listType=buy&good.goodName=oo" id="buy">买&nbsp;家 &nbsp;圈</a> <a
				href="getGoodbyType.action?good.type=0&good.listType=sale&good.goodName=oo" id=sale>卖&nbsp;家 &nbsp;圈</a> 
	</div>
		</div>
		
<!-- 联系客服 -->

    <div class="content" style="position:fixed;top:15%;left:30%;margin-top:40%">
        <div class="chatBox" >
            <div class="chatLeft">
                <div class="chat01">
                    <div class="chat01_title">
                        <ul class="talkTo">
                            <li><a href="javascript:;">客服</a></li></ul>
                        <a class="close_btn" href="#"></a>
                    </div>
                    <div class="chat01_content">
                    </div>
                </div>
                <div class="chat02">
                    <div class="chat02_title">
                       
                        <div class="wl_faces_box">
                            <div class="wlf_icon">
                            </div>
                        </div>
                    </div>
                    <div class="chat02_content">
                        <textarea id="textarea"></textarea>
                    </div>
                    <div class="chat02_bar">
                        <ul>
                           
                            <li  id="send" style="right: 5px; top: 5px;"><a href="javascript:;">
                                <img src="img/send_btn.jpg"></a></li>
                        </ul>
                    </div>
                </div>
            </div>
            <div style="clear: both;">
            </div>
        </div>
    </div>

	
		
  <iframe src='iframes/buys.jsp' name="buyframe" id="two" width="103%" onload="changeFrameHeight()"  scrolling="yes" marginheight="0" marginwidth="0" frameborder="0"></iframe>
		
  <br/><br/><br/>
</body>